﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public class AB45ONData : ABONData
    { 
        public string UserGroup;
        public string MANDANT = "00";
        public string SPRACHKZ;
        public AB45ONData()
            : base()
        {

        }
        public AB45ONData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {

        }
        public AB45ONData(OracleConnection _myConnection, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_myConnection, _proxy, userID)
        {

        }
        public DataSet InsertAB45POS(DataRow dwBAAUF,DataSet setInput, DataRow dwAB55, double ReqQtyMTR, string ABKAUFART,
            double Wnum=100,string KRS = "T5", int LeadTime = 14)
        {
            #region============VARIABLE====================
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataRow dwWASTAMM = null, dwAPZUORD = null;
            DataRow dwLocal = null, dwBHSATZ=null;
            DataTable tableLocal = null;
            OracleCommand or1;
            string LFD = "000000", POS = "010";
            string ABPART = "", ABPVAR = "", WDPRART = "", WDPRVAR = "";
            string ABPSME = "2";
            double ABPSOLLMENGE1 = 0, ABPSOLLMENGE2 = 0, ABPSOLLMENGE3 = 0, ABPSOLLMENGE4 = 0,
                ABPSOLLMENGE5 = 0, ABPSOLLMENGE6 = 0, ABPSOLLMENGE7 = 0, ABPSOLLMENGE8 = 0;
            string ABPNEUBEN = "SUNLV   ";
            string ABPNEUDAT = "20110823", STARTDATE = "20110822", ENDDATE = "20110826";
            string APZALFDNR = " ", APZANRKRS = " ";
            #endregion
            try
            {
                or1 = OracleDB.CreateCommand();

                #region============GETNUMBER======================
                LFD = GetAUFLFD(KRS);
                #endregion

                #region============BEAMMASTER=================
                ABPART = dwBAAUF["BAKART"].ToString();
                ABPVAR = dwBAAUF["BAKVAR"].ToString();

                dwBHSATZ = setInput.Tables["BHSATZ"].Rows[0];
                #endregion

                #region============APZUORD======================
                setResult = GetAPZUORD(ABPART, ABPVAR, "K");
                if (setResult.Tables.Count > 0)
                {
                    if (setResult.Tables[0].Rows.Count > 0)
                    {
                        dwAPZUORD = setResult.Tables[0].Rows[0];
                    }
                }
                if (dwAPZUORD != null)
                { 
                    APZANRKRS = dwAPZUORD["APZANRKRS"].ToString();
                    APZALFDNR = dwAPZUORD["APZALFDNR"].ToString();
                }
                #endregion

                #region============MAPDATA=========================
                dwLocal = setINTEX.ABPOS1.NewRow();
                ABPNEUBEN = UserID;
                ABPNEUDAT = iDate;
                ENDDATE = dwBAAUF["BADATVON"].ToString();
                STARTDATE = GetDateAddDays(ENDDATE, 0 - LeadTime);
                dwLocal["ABPMANDANT"] = dwBAAUF["BAMANDANT"].ToString();
                dwLocal["ABPAUFKRS"] = KRS;
                dwLocal["ABPAUFLFD"] = LFD;
                dwLocal["ABPAUFPOS"] = POS;
                dwLocal["ABPAUFART"] = ABKAUFART;
                dwLocal["ABPNEUBEN"] = ABPNEUBEN;
                dwLocal["ABPNEUDAT"] = ABPNEUDAT;
                dwLocal["ABPART"] = ABPART;
                dwLocal["ABPVAR"] = ABPVAR;
                dwLocal["ABPWAKZ"] = "K";
                dwLocal["ABPFARBE"] = dwBAAUF["BAKFARBE"].ToString();

                dwLocal["ABPLAEAENDA"] = 0;
                dwLocal["ABPSTDLAE"] = 0; 
                ABPSME = "1";
                dwLocal["ABPSME"] = ABPSME;
                dwLocal["ABPENDDATA"] = ENDDATE;
                dwLocal["ABPLIEFDAT"] = ENDDATE;
                dwLocal["ABPENDDAT"] = ENDDATE;
                dwLocal["ABPLIEFDATN"] = ENDDATE;
                dwLocal["ABPENDDATA"] = ENDDATE;
            
                dwLocal["ABPSTARTDAT"] = STARTDATE;
                dwLocal["ABPSTARTDATA"] = STARTDATE;
                dwLocal["ABPVTDATE"] = iDate;
                dwLocal["ABPTERMDAT"] = ENDDATE;
                dwLocal["ABPSTARTDATN"] = STARTDATE;  
                
                dwLocal["ABPANRKR"] = APZANRKRS;
                dwLocal["ABPALFDNR"] = APZALFDNR;

               
                ABPSOLLMENGE1 = System.Convert.ToInt64(System.Math.Round(ReqQtyMTR*10.0,0));
                ABPSOLLMENGE2 = ABPSOLLMENGE1;
                double BHKGNET = System.Convert.ToDouble(dwBHSATZ["BHKGNET"]);
                ABPSOLLMENGE3 = 0;
                ABPSOLLMENGE4 = 0;
                ABPSOLLMENGE5 = System.Convert.ToDouble(System.Math.Round(ABPSOLLMENGE1*0.001 * (BHKGNET * 0.001), 0));
                ABPSOLLMENGE6 = ABPSOLLMENGE5;
                ABPSOLLMENGE7 = Wnum;
                ABPSOLLMENGE8 = Wnum;
                dwLocal["ABPSOLLMENGE1"] = ABPSOLLMENGE1;
                dwLocal["ABPSOLLMENGE2"] = ABPSOLLMENGE2;
                dwLocal["ABPSOLLMENGE3"] = ABPSOLLMENGE3;
                dwLocal["ABPSOLLMENGE4"] = ABPSOLLMENGE4;
                dwLocal["ABPSOLLMENGE5"] = ABPSOLLMENGE5;
                dwLocal["ABPSOLLMENGE6"] = ABPSOLLMENGE6;
                dwLocal["ABPSOLLMENGE7"] = ABPSOLLMENGE7;
                dwLocal["ABPSOLLMENGE8"] = ABPSOLLMENGE8; 

                dwLocal["ABPAENDBEN"] = ABPNEUBEN;
                dwLocal["ABPAENDDAT"] = ABPNEUDAT;
                dwLocal["ABPZLO"] = "00";
                dwLocal["ABPZLB"] = "00";
                dwLocal["ABPBLO"] = "01";
                dwLocal["ABPAESTAT"] = "J";
                
                #endregion
             
                #region============INSERT==========================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "INSERT INTO ABPOS(ABPMANDANT, ABPAUFKRS, ABPAUFLFD, ABPAUFPOS, ABPVFAUFKRS, ABPVFAUFLFD, ABPVFAUFPOS, ABPAUFART, ABPAUFST, ABPAUFSTV, ABPAUFSTB, ABPAUTO, ABPPRIO, ABPTLVF, ABPDIVARTKZ, ABPKUNDNR, ABPWERK, ABPABT, ABPWAKZ, ABPART, ABPVAR, ABPFARBE, ABPDESS, ABPCOLORIT, ABPBESCHICH, ABPGROE, ABPAUFM, ABPVERP, ABPANZVP, ABPFWARTGRA, ABPFWARTGRP, ABPZLO, ABPZLB, ABPBLO, ABPSME, ABPSOLLMENGE1, ABPSOLLMENGE2, ABPSOLLMENGE3, ABPSOLLMENGE4, ABPSOLLMENGE5, ABPSOLLMENGE6, ABPSOLLMENGE7, ABPSOLLMENGE8, ABPRESMGE, ABPRESKG, ABPRESSTK, ABPZUGET, ABPZUGKG, ABPZUGSTK, ABPDILFM, ABPDIKG, ABPDISTK, ABPZTLGKOMP, ABPSMGKZZU, ABPVLLFM, ABPVLKG, ABPVLSTK, ABPEALFM, ABPEAKG, ABPEASTK, ABPEBLFM, ABPEBKG, ABPEBSTK, ABPABLFM, ABPABKG, ABPABSTK, ABPVSLFM, ABPVSKG, ABPVSSTK, ABPRTLFM, ABPRTKG, ABPRTSTK, ABPROHWDAT, ABPKDDAT, ABPWVDAT, ABPLIEFDAT, ABPLRUECK, ABPLRDATE, ABPDLR, ABPVTRUECK, ABPVTDATE, ABPUNKLAR, ABPVERSDAT, ABPFREIDAT, ABPSTARTDAT, ABPENDDAT, ABPSTARTDATA, ABPENDDATA, ABPLTERMAK, ABPBESTDAT, ABPANRKR, ABPALFDNR, ABPAFOLGEV, ABPAFOLGEB, ABPANRKR2, ABPALFDNR2, ABPAFOLGEV2, ABPAFOLGEB2, ABPANRKR3, ABPALFDNR3, ABPAFOLGEV3, ABPAFOLGEB3, ABPANRKR4, ABPALFDNR4, ABPAFOLGEV4, ABPAFOLGEB4, ABPVERSAEND, ABPVERSZL, ABPTLFREIG, ABPTLFMG, ABPFREIGKZ, ABPLMAFOLGE, ABPENDAUFM, ABPZAUFM, ABPLIEFNR, ABPGESSTA, ABPKDSTA, ABPWSSTA, ABPAPSTA, ABPRZSTA, ABPWPSTA, ABPWBSTA, ABPABSTA, ABPERLKZ, ABPERLDAT, ABPBEWKZ, ABPDRKZ1, ABPDRKZ2, ABPDRKZ3, ABPDRKZ4, ABPDRKZ5, ABPDRKZ6, ABPDRKZ7, ABPDRKZ8, ABPDRKZ9, ABPDRKZ10, ABPDR1USER, ABPDR1DAT, ABPDR8USER, ABPDR8DAT, ABPRETOURZL, ABPRPCOUNTAK, ABPURAUFKRS, ABPURAUFLFD, ABPURAUFPOS, ABPASAUFKRS, ABPASAUFLFD, ABPASAUFPOS, ABPREAFOLGE, ABPRWKRS, ABPRWLFD, ABPSTKNRKR, ABPSERIE, ABPAGBKZ, ABPWAART, ABPANZSTK, ABPZUGETGES, ABPSTKKZ, ABPSTKLG, ABPANZSTKR, ABPABZKZ, ABPBDEKZ, ABPSUBSYS, ABPDATBDE, ABPUHRBDE, ABPDISPOKZ, ABPSCHLICHTE, ABPZZUSATZ, ABPZZUSKZ, ABPSZUSTAND, ABPIZUSTAND, ABPSZUSATZKZ1, ABPSZUSATZKZ2, ABPSZUSATZKZ3, ABPSZUSATZKZ4, ABPWERKE, ABPLBMUSTR, ABPFBMUSTR, ABPREAUFKRS, ABPREAUFLFD, ABPREAUFPOS, ABPLTVORL, ABPFDZ, ABPARTEX, ABPLETEILNR, ABPANSNR, ABPUPOS, ABPTP, ABPLBDENR, ABPTMCOUNT, ABPTMCOUNTAK, ABPKDPARTIE, ABPBAHNKZ, ABPGAENGE, ABPZWTWAHL, ABPDIVWLFM, ABPDIVWKG, ABPDISPOST, ABPKETTAUFT, ABPKETTGARN, ABPSPGRD, ABPSPBENID, ABPSPDAT, ABPLMDAT, ABPLMZT, ABPWPLKZ, ABPKKUNDNR, ABPKLAND, ABPKVB, ABPKVG, ABPKPROGRP, ABPKARTGRP, ABPKVKZ, ABPLAEVON, ABPLAEBIS, ABPSTDLAE, ABPMGV, ABPMGB, ABPPAS, ABPPAI, ABPAZUTEIL, ABPZUTART, ABPFA, ABPGA, ABPQA, ABPMAFZST, ABPQPKTH, ABPQPKTLH, ABPSTKNEUTR, ABPREGEL, ABPSTAFFNR, ABPWERKEKZ, ABPWKSTKRS, ABPWKST, ABPWKART, ABPWMNRKRS, ABPWMLFDNR, ABPWMPOS, ABPWMODNR, ABPWINTV, ABPWKENN, ABPWSTOERGRD, ABPWAKSTKRS, ABPWAKST, ABPWPERSNR, ABPWDATV, ABPWZEITV, ABPWDATB, ABPWZEITB, ABPWSTA, ABPFKALK, ABPLIEFDATN, ABPLAEAENDE, ABPLAEAENDA, ABPDMWAKZ, ABPDMART, ABPDMVAR, ABPDMDESS, ABPDMCOLORIT, ABPDMFARBE, ABPDMBESCHICH, ABPDKART, ABPDKVAR, ABPDKFARBE, ABPDKBRUT, ABPGENEHMKZ, ABPSTUEART, ABPCOMPKZ, ABPPOSTYP, ABPORDER, ABPNPGRUND, ABPREWEIL, ABPFSCHL, ABPKSTKRS, ABPKST, ABPMURW, ABPMUVB, ABPMUFW, ABPMUPF, ABPERSTFB, ABPERSTDR, ABPERSTBE, ABPMUCTOD, ABPKDFREI, ABPREZFB, ABPREZDR, ABPPRUEF, ABPNIXWE, ABPCOLSTA, ABPFBSTA, ABPBAHNNR, ABPBAHNBRT, ABPFLBEDECK, ABPDATABDE, ABPUHRABDE, ABPLOEKZ, ABPTERMDAT, ABPPRFI, ABPPRVAR, ABPPRBE, ABPPRZU, ABPPRDESS, ABPZUSATZ1, ABPZUSATZ2, ABPZUSATZ3, ABPZUSATZ4, ABPZUSATZ5, ABPFLAG1, ABPFLAG2, ABPFLAG3, ABPFLAG4, ABPFLAG5, ABPORGMG, ABPDIFFMG, ABPRARTKZ, ABPSTARTDATN, ABPAESTAT, ABPLBAUFKRS, ABPLBAUFLFD, ABPLBAUFPOS, ABPVEAUFTRAG, ABPREGBLOG, ABPREGBDATE, ABPPROJNR, ABPSHADE, ABPSHADEUNCL, ABPLICHTART, ABPLINE, ABPFILLER1, ABPAENDZL, ABPAENDBEN, ABPAENDDAT, ABPNEUBEN, ABPNEUDAT)"
                + "VALUES (:ABPMANDANT, :ABPAUFKRS, :ABPAUFLFD, :ABPAUFPOS, '  ', '000000', '000',:ABPAUFART, ' ', '0', '0', ' ', '00', '   ', ' ', '00000000', '   ', '   '"
                + ", 'K', '                    ', '   ', '          ', '          ', '          ', '          ', '       ', '  ', '   ', 0, '     ', '  ', '  ', '  ', '  ', '1', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0"
                + ", 0, 0, 0, '  ', 0, 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, '  ', '      ', '000', '000', '  ', '000000', 0, 0, '  ', '000000', 0, 0, '  ', '000000', 0, 0, ' ', '006', '000', 0, ' ', '000', '  ', '  ', '        ', 'TE', '10'"
                + ", '20', '30', '40', '50', '60', '70', ' ', 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '        ', '00000000', '        ', '00000000', 0, 0, '  ', '000000', '000', '  ', '000000', '000', '000', '  ', '000000'"
                + ", '  ', 'SZ', ' ', '   ', 0, 0, ' ', 0, 0, ' ', 'N', '  ', 0, 0, ' ', '     ', '          ', ' ', '    ', '    ', ' ', ' ', ' ', ' ', ' ', '   ', '   ', '  ', '000000', '000', '               ', 0, '                                                            '"
                + ", 0, 0, 0, 0, 0, 1, 0, '          ', ' ', 0, 0, 0, 0, ' ', ' ', ' ', '  ', '        ', 0, 0, 0, ' ', '        ', '   ', '   ', '   ', '   ', '   ', ' ', 0, 0, 0, 0, 0, 0, 0, ' ', ' ', 0, 0, 0, 0, 0, 0, ' ', '00000000', '00', ' ', '  ', '0000'"
                + ", '000000', '  ', '0000', '00', '000', '00', '  ', '               ', '  ', '0000', '        ', 0, 0, 0, 0, '  ', ' ', 0, 0, 0, ' ', '                    ', '  ', '          ', '          ', '          ', '          ', '                    '"
                + ", '  ', '  ', 0, ' ', '   ', ' ', '   ', '    ', '   ', '  ', '   ', '  ', '0000', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '0', 0, 0, '00000000', '000000', ' ', '        ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0"
                + ", 0, 0, 0, 0, 0, 0, ' ', '        ', ' ', '  ', '000000', '000', '               ', 0, 0, '                        ', '   ', ' ', '     ', '   ', '                                                                                                      '"
                + ", 1, '        ', 0,:ABPNEUBEN, :ABPNEUDAT)";
                or1.Parameters.Add("ABPMANDANT", OracleType.NVarChar).Value = dwLocal["ABPMANDANT"];
                or1.Parameters.Add("ABPAUFKRS", OracleType.NVarChar).Value = dwLocal["ABPAUFKRS"];
                or1.Parameters.Add("ABPAUFLFD", OracleType.NVarChar).Value = dwLocal["ABPAUFLFD"];
                or1.Parameters.Add("ABPAUFPOS", OracleType.NVarChar).Value = dwLocal["ABPAUFPOS"];
                or1.Parameters.Add("ABPAUFART", OracleType.NVarChar).Value = dwLocal["ABPAUFART"];
                or1.Parameters.Add("ABPNEUBEN", OracleType.NVarChar).Value = dwLocal["ABPNEUBEN"];
                or1.Parameters.Add("ABPNEUDAT", OracleType.NVarChar).Value = dwLocal["ABPNEUDAT"];
                setResult = Connect2Proxy(or1);

                #endregion

                #region============UPDATE=========================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "UPDATE ABPOS SET "
                    + " ABPWAKZ=:ABPWAKZ,ABPART=:ABPART,ABPVAR=:ABPVAR,ABPFARBE=:ABPFARBE"
                    + " ,ABPSME=:ABPSME,ABPSOLLMENGE1=:ABPSOLLMENGE1,ABPSOLLMENGE2=:ABPSOLLMENGE2,ABPSOLLMENGE3=:ABPSOLLMENGE3"
                    + ",ABPSOLLMENGE4=:ABPSOLLMENGE4,ABPSOLLMENGE5=:ABPSOLLMENGE5,ABPSOLLMENGE6=:ABPSOLLMENGE6,ABPSOLLMENGE7=:ABPSOLLMENGE7"
                    + ",ABPSOLLMENGE8=:ABPSOLLMENGE8"
                    + ",ABPSTDLAE=:ABPSTDLAE,ABPLAEAENDA=:ABPLAEAENDA"
                    + ",ABPENDDAT=:ABPENDDAT,ABPENDDATA=:ABPENDDATA,ABPLIEFDAT=:ABPLIEFDAT,ABPLIEFDATN=:ABPLIEFDATN,ABPSTARTDAT=:ABPSTARTDAT,ABPSTARTDATA=:ABPSTARTDATA,ABPVTDATE=:ABPVTDATE,ABPTERMDAT=:ABPTERMDAT"
                    + ",ABPSTARTDATN=:ABPSTARTDATN"
                    + ",ABPZLO=:ABPZLO,ABPZLB=:ABPZLB,ABPBLO=:ABPBLO,ABPAESTAT=:ABPAESTAT" 
                    + " ,ABPANRKR=:ABPANRKR, ABPALFDNR=:ABPALFDNR"
                    + ",ABPAENDBEN=:ABPAENDBEN,ABPAENDDAT=:ABPAENDDAT,ABPAUFART=:ABPAUFART"
                    + " WHERE ABPMANDANT=:ABPMANDANT AND ABPAUFKRS=:ABPAUFKRS AND ABPAUFLFD=:ABPAUFLFD AND ABPAUFPOS=:ABPAUFPOS";
                

                or1.Parameters.Add("ABPMANDANT", OracleType.NVarChar).Value = dwLocal["ABPMANDANT"];
                or1.Parameters.Add("ABPAUFKRS", OracleType.NVarChar).Value = dwLocal["ABPAUFKRS"];
                or1.Parameters.Add("ABPAUFLFD", OracleType.NVarChar).Value = dwLocal["ABPAUFLFD"];
                or1.Parameters.Add("ABPAUFPOS", OracleType.NVarChar).Value = dwLocal["ABPAUFPOS"];
                
                or1.Parameters.Add("ABPWAKZ", OracleType.NVarChar).Value = dwLocal["ABPWAKZ"];
                or1.Parameters.Add("ABPART", OracleType.NVarChar).Value = dwLocal["ABPART"];
                or1.Parameters.Add("ABPVAR", OracleType.NVarChar).Value = dwLocal["ABPVAR"];
                or1.Parameters.Add("ABPFARBE", OracleType.NVarChar).Value = dwLocal["ABPFARBE"];

                or1.Parameters.Add("ABPSME", OracleType.NVarChar).Value = dwLocal["ABPSME"]; 
                or1.Parameters.Add("ABPSOLLMENGE1", OracleType.NVarChar).Value = dwLocal["ABPSOLLMENGE1"];
                or1.Parameters.Add("ABPSOLLMENGE2", OracleType.NVarChar).Value = dwLocal["ABPSOLLMENGE2"];
                or1.Parameters.Add("ABPSOLLMENGE3", OracleType.NVarChar).Value = dwLocal["ABPSOLLMENGE3"];
                or1.Parameters.Add("ABPSOLLMENGE4", OracleType.NVarChar).Value = dwLocal["ABPSOLLMENGE4"];
                or1.Parameters.Add("ABPSOLLMENGE5", OracleType.NVarChar).Value = dwLocal["ABPSOLLMENGE5"];
                or1.Parameters.Add("ABPSOLLMENGE6", OracleType.NVarChar).Value = dwLocal["ABPSOLLMENGE6"];
                or1.Parameters.Add("ABPSOLLMENGE7", OracleType.NVarChar).Value = dwLocal["ABPSOLLMENGE7"];
                or1.Parameters.Add("ABPSOLLMENGE8", OracleType.NVarChar).Value = dwLocal["ABPSOLLMENGE8"];
                
                or1.Parameters.Add("ABPSTDLAE", OracleType.NVarChar).Value = dwLocal["ABPSTDLAE"];
                or1.Parameters.Add("ABPLAEAENDA", OracleType.NVarChar).Value = dwLocal["ABPLAEAENDA"];

                or1.Parameters.Add("ABPENDDAT", OracleType.NVarChar).Value = dwLocal["ABPENDDAT"];
                or1.Parameters.Add("ABPENDDATA", OracleType.NVarChar).Value = dwLocal["ABPENDDATA"];
                or1.Parameters.Add("ABPLIEFDAT", OracleType.NVarChar).Value = dwLocal["ABPLIEFDAT"];
                or1.Parameters.Add("ABPLIEFDATN", OracleType.NVarChar).Value = dwLocal["ABPLIEFDATN"];
                or1.Parameters.Add("ABPSTARTDAT", OracleType.NVarChar).Value = dwLocal["ABPSTARTDAT"];
                or1.Parameters.Add("ABPSTARTDATA", OracleType.NVarChar).Value = dwLocal["ABPSTARTDATA"];
                or1.Parameters.Add("ABPVTDATE", OracleType.NVarChar).Value = dwLocal["ABPVTDATE"];
                or1.Parameters.Add("ABPTERMDAT", OracleType.NVarChar).Value = dwLocal["ABPTERMDAT"];
                or1.Parameters.Add("ABPSTARTDATN", OracleType.NVarChar).Value = dwLocal["ABPSTARTDATN"];
                or1.Parameters.Add("ABPZLO", OracleType.NVarChar).Value = dwLocal["ABPZLO"];
                or1.Parameters.Add("ABPZLB", OracleType.NVarChar).Value = dwLocal["ABPZLB"];
                or1.Parameters.Add("ABPBLO", OracleType.NVarChar).Value = dwLocal["ABPBLO"];
                or1.Parameters.Add("ABPAESTAT", OracleType.NVarChar).Value = dwLocal["ABPAESTAT"];
                
                or1.Parameters.Add("ABPANRKR", OracleType.NVarChar).Value = dwLocal["ABPANRKR"];
                or1.Parameters.Add("ABPALFDNR", OracleType.NVarChar).Value = dwLocal["ABPALFDNR"]; 

                or1.Parameters.Add("ABPAUFART", OracleType.NVarChar).Value = dwLocal["ABPAUFART"];
                or1.Parameters.Add("ABPAENDBEN", OracleType.NVarChar).Value = dwLocal["ABPAENDBEN"];
                or1.Parameters.Add("ABPAENDDAT", OracleType.NVarChar).Value = dwLocal["ABPAENDDAT"];
                setResult = Connect2Proxy(or1);
                #endregion

                #region============SELECT==========================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM ABPOS "
                + " WHERE ABPMANDANT=:ABPMANDANT AND ABPAUFKRS=:ABPAUFKRS AND ABPAUFLFD= :ABPAUFLFD AND ABPAUFPOS= :ABPAUFPOS";

                or1.Parameters.Add("ABPMANDANT", OracleType.NVarChar).Value = dwLocal["ABPMANDANT"];
                or1.Parameters.Add("ABPAUFKRS", OracleType.NVarChar).Value = dwLocal["ABPAUFKRS"];
                or1.Parameters.Add("ABPAUFLFD", OracleType.NVarChar).Value = dwLocal["ABPAUFLFD"];
                or1.Parameters.Add("ABPAUFPOS", OracleType.NVarChar).Value = dwLocal["ABPAUFPOS"];
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "ABPOS";
                }
                setReturn.Merge(setResult);
                #endregion
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }

        public override DataSet InsertABAUFM(DataRow dwABPOS, DataRow dwBAAUF, DataRow dwAB55)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            OracleCommand or1;
            DataRow dwLocal;
            DataRow dwBSGROE = null;
            string BSGKETTART = "PICA  ";
            try
            {
                WarpMasterData m_WM = new WarpMasterData(OracleDB, proxy);
                DataRow dwBSFARB = setINTEX.BSFARB.NewRow();
                dwBSFARB["BSFKART"] = dwABPOS["ABPART"];
               setResult= m_WM.GetBS31(dwBSFARB);
               
               if (setResult.Tables.Count > 0)
               {
                   foreach (DataRow dwTemp in setResult.Tables[0].Rows)
                   {
                       dwBSGROE = dwTemp;
                   }
               }
               if (dwBSGROE != null)
               {

                   BSGKETTART = dwBSGROE["BSGKETTART"].ToString();
               }
                
                #region============MAPDATA=========================
                dwLocal = setINTEX.ABAUFM.NewABAUFMRow();
                dwLocal["ABAMANDANT"] = dwABPOS["ABPMANDANT"];
                dwLocal["ABAAUFTYP"] = "V";
                dwLocal["ABAAUFKRS"] = dwABPOS["ABPAUFKRS"];
                dwLocal["ABAAUFLFD"] = dwABPOS["ABPAUFLFD"];
                dwLocal["ABAAUFPOS"] = dwABPOS["ABPAUFPOS"];
                dwLocal["ABANEUBEN"] = dwABPOS["ABPNEUBEN"];
                dwLocal["ABANEUDAT"] = dwABPOS["ABPNEUDAT"];

                string ABPSME = dwABPOS["ABPSME"].ToString();
                long ABASGESLG = 0;
                string ABALEAPOS = "2", ABASME = "2";
                ABASME = ABPSME;
                switch (ABPSME)
                {
                    case "1":
                        ABASGESLG = System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE1"].ToString()) * 10;
                        break;
                    case "2":
                        ABASGESLG = System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE2"].ToString()) * 10;
                        break;
                    case "3":
                        ABASGESLG = System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE3"].ToString()) * 10;
                        break;
                    case "4":
                        ABASGESLG = System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE4"].ToString()) * 10;
                        break;
                    case "5":
                        ABASGESLG = System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE5"].ToString()) * 10;
                        break;
                    case "6":
                        ABASGESLG = System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE6"].ToString()) * 10;
                        break;
                    case "7":
                        ABASGESLG = System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE7"].ToString()) * 10;
                        break;
                    case "8":
                        ABASGESLG = System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE8"].ToString()) * 10;
                        break;
                    default:
                        break;
                }
                double Wnum = System.Math.Round(System.Convert.ToDouble(dwABPOS["ABPSOLLMENGE8"].ToString()) * 0.010, 0);
                dwLocal["ABASANZSTK"] = Wnum;
                double ABASSTKLG = System.Math.Round(System.Convert.ToDouble(dwABPOS["ABPSOLLMENGE1"].ToString()) * 10 / Wnum, 0);
                dwLocal["ABASSTKLG"] = ABASSTKLG;
                dwLocal["ABASSTKLGV"] = ABASSTKLG - 2000;
                dwLocal["ABASSTKLGB"] = ABASSTKLG +2000;
                dwLocal["ABASGESGEW"] = System.Math.Round(System.Convert.ToDouble(dwABPOS["ABPSOLLMENGE5"].ToString()) * 10, 0);
                

                #endregion

                #region============INSERT0001======================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "INSERT INTO ABAUFM(ABAMANDANT, ABAAUFTYP, ABAAUFKRS, ABAAUFLFD, ABAAUFPOS, ABAAPOS, ABAERLKZ, ABARESMG, ABASANZSTK, ABASSTKLG, ABASSTKLGV, ABASSTKLGB, ABASSTKGEW, ABASSTKGEWV, ABASSTKGEWB, ABASSTKBRT, ABASSTKBRTV, ABASSTKBRTB, ABAIANZSTK, ABAIZENSUR1, ABAIZENSURKZ1, ABAIZENSUR2, ABAIZENSURKZ2, ABAIGESLGZS1, ABAIGESLGZS2, ABASTDPOS, ABASFERTKZ, ABAUEBKZ, ABAUMAILKZ, ABASGESLG, ABASGESGEW, ABASME, ABAFRMG, ABARSTSLG, ABARSTSGEW, ABAMINUSLG, ABAMINUSGEW, ABALEAPOS, ABAPOOL, ABARESFLAG, ABAVKAUFTYP, ABAVKAUFKRS, ABAVKAUFLFD, ABAVKAUFPOS, ABAVKUPOS, ABAVB, ABAVG, ABAZUPRIO, ABASTKNEUTR, ABARESPROG, ABARESBEN, ABARESDAT, ABARESZEIT, ABARVSACHB, ABARKUNDNR, ABARBISDAT, ABAVLVB, ABAVLVG, ABAVLSACHB, ABAVLGEGEN, ABAPRKUNDNR, ABAPRAUFKRS, ABAPRAUFLFD, ABAPRAUFPOS, ABAGENEHM, ABAGSACHB, ABALIEFNR, ABAVSACHB, ABAVSTKNR, ABAVERSWEG, ABAMVERSDAT, ABAWVDAT, ABGENDAT, ABAGENNR, ABAGENNAME, ABAGENWEG, ABAZUSTK, ABAZULG, ABAOPTKZ, ABAMAFZST, ABAPART1, ABAPARTST1, ABAPART2, ABAPARTST2, ABAPART3, ABAPARTST3, ABAPART4, ABAPARTST4, ABAPART5, ABAPARTST5, ABAPART6, ABAPARTST6, ABAPART7, ABAPARTST7, ABAPART8, ABAPARTST8, ABAPART9, ABAPARTST9, ABAPART10, ABAPARTST10, ABASZENSUR, ABASZENSURKZ, ABAKUTLSTK, ABABAHNKZ, ABAWDUPOS, ABABAHNEN, ABATEILKZ, ABAKUNDNRU, ABAWERKU, ABAABTU, ABAARTU, ABAVARU, ABADESSU, ABACOLORITU, ABAFARBEU, ABABESCHU, ABAFARBBEZU, ABAANZ1, ABALAENGE1, ABABREITE1, ABAANZ2, ABALAENGE2, ABABREITE2, ABAANZ3, ABALAENGE3, ABABREITE3, ABAANZ4, ABALAENGE4, ABABREITE4, ABAANZ5, ABALAENGE5, ABABREITE5, ABAVERSDAT, ABAVATYP, ABAANZORG, ABAANZKOP, ABAVERSART, ABASPED, ABALIEFKD, ABAVERSKD, ABAADRSLL, ABAVAKZ, ABALIEFKOMP, ABATEILNR, ABAVDPKZ, ABATPMA, ABABOXMAX, ABABOXANZ, ABALGEBNR, ABANKGEB, ABAIFEUCHTE, ABAKUNDNR, ABASTKNR, ABAPARTIE, ABAPARTIEKZ, ABAKDPARTIE, ABAKDAUFTNR, ABAKDAUFDAT, ABAMAART, ABASTKLFDNR, ABAAUFMSL, ABAZUSAM, ABAPACKTYP, ABATAX, ABAHUELSE, ABAWOBST, ABAWICKL, ABAFDRES, ABAKF, ABANRVERG, ABASTKNRKRS, ABASUFFART, ABATRENNZ, ABALAENGEU, ABALAENGES, ABASCHRITW, ABAFUELLZ, ABAASSCHNIT, ABAETITYP, ABAANZRET, ABAKDETKZ, ABADOPPEL, ABALOAN, ABALBAN, ABALPAN, ABAAUFBKZAN, ABALOA2, ABALBA2, ABALPA2, ABAABKZA2, ABAPKL, ABABEM1, ABABEM2, ABAMRKM1, ABAMRKM2, ABAMRKM3, ABAKZNTO, ABAFESP, ABADIAUFKRS, ABADIAUFLFD, ABADIAUFPOS, ABADILG, ABADIGEW, ABADISTK, ABADISLG, ABADISGEW, ABABA, ABAASGESLG, ABAASGESGEW, ABAPNRKRS, ABAPLFDNR, ABAGKREGEL, ABAPROVOR, ABAPRSFE, ABAWSCHTXT, ABAVORSGEL, ABASELVL, ABASELVR, ABAKOLL, ABAVKART, ABAVKFARBE, ABAGBEDKZ, ABADL, ABAKDPARTKZ, ABAFILLER, ABAAENDZL, ABAAENDBEN, ABAAENDDAT, ABANEUBEN, ABANEUDAT)"
                    + "VALUES (:ABAMANDANT, :ABAAUFTYP, :ABAAUFKRS, :ABAAUFLFD, :ABAAUFPOS, '0001', ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', ' ', 0, 0, 1, ' ', ' ', ' '"
                + ", 0, 0, ' ', 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', '  ', '000000', '000', '00', '   ', '   ', '9', ' ', '        ', '        ', 0, 0, '        ', '        ', 0, '   ', '   ', '        ', ' ', '        ', '  ', '000000', '000', ' ', '        ', '        ', '        ', '            ', '  ', 0, 0, 0, '            ', '                              ', '  ', 0, 0, ' ', 0, '           ', 0, '           ', 0, '           ', 0, '           ', 0, '           ', 0, '           ', 0, '           ', 0, '           ', 0, '           ', 0, '           ', 0, ' ', ' ', 0, ' ', 1, 0, ' ', '        ', '   ', '   ', '                    ', '   ', '          ', '          ', '          ', '          ', '                    ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '  ', 0, 0, '   ', '   ', '        ', '        ', '        ', 'J', ' ', 0, ' ', '    ', 0, 0, '        ', '  ', 0, '00000000', '            ', '0000000', ' ', '          ', '                    ', 0, ' ', 0, '  ', '  ', '    ', '   ', '      ', ' ', ' ', ' ', ' ', ' ', '  ', ' ', ' ', 0, 0, 0, ' ', 'N', '  ', 0, ' ', '          ', '  ', '  ', '        ', ' ', '  ', '  ', '        ', ' ', '  ', '                                                            ', '                                                            ', '    ', '    ', '    ', ' ', ' ', '  ', '000000', '000', 0, 0, 0, 0, 0, '      ', 0, 0, '  ', '000000', '00000000', '        ', 0, '   ', ' ', 0, 0, '     ', '                        ', '          ', ' ', ' ', ' ', '                                                                                    ', 1, '        ', 0"
                + ", :ABANEUBEN, :ABANEUDAT)";
                or1.Parameters.Add("ABAMANDANT", OracleType.NVarChar).Value = dwLocal["ABAMANDANT"];
                or1.Parameters.Add("ABAAUFTYP", OracleType.NVarChar).Value = dwLocal["ABAAUFTYP"];
                or1.Parameters.Add("ABAAUFKRS", OracleType.NVarChar).Value = dwLocal["ABAAUFKRS"];
                or1.Parameters.Add("ABAAUFLFD", OracleType.NVarChar).Value = dwLocal["ABAAUFLFD"];
                or1.Parameters.Add("ABAAUFPOS", OracleType.NVarChar).Value = dwLocal["ABAAUFPOS"];
                or1.Parameters.Add("ABANEUBEN", OracleType.NVarChar).Value = dwLocal["ABANEUBEN"];
                or1.Parameters.Add("ABANEUDAT", OracleType.NVarChar).Value = dwLocal["ABANEUDAT"];
                setResult = Connect2Proxy(or1);
                #region============UPDATE0001======================
                or1 = OracleDB.CreateCommand();

                or1.CommandText = "UPDATE ABAUFM SET "
                    + "ABASGESLG=:ABASGESLG,ABASANZSTK=:ABASANZSTK,ABASME=:ABASME,ABALEAPOS=:ABALEAPOS,ABASSTKLG=:ABASSTKLG"
                + ",ABASSTKLGV=:ABASSTKLGV,ABASSTKLGB=:ABASSTKLGB,ABABA=:ABABA,ABASGESGEW=:ABASGESGEW"
                + " WHERE ABAMANDANT=:ABAMANDANT AND ABAAUFTYP=:ABAAUFTYP AND ABAAUFKRS=:ABAAUFKRS AND ABAAUFLFD=:ABAAUFLFD AND ABAAUFPOS=:ABAAUFPOS AND ABAAPOS=:ABAAPOS";
                or1.Parameters.Add("ABAMANDANT", OracleType.NVarChar).Value = dwLocal["ABAMANDANT"];
                or1.Parameters.Add("ABAAUFTYP", OracleType.NVarChar).Value = dwLocal["ABAAUFTYP"];
                or1.Parameters.Add("ABAAUFKRS", OracleType.NVarChar).Value = dwLocal["ABAAUFKRS"];
                or1.Parameters.Add("ABAAUFLFD", OracleType.NVarChar).Value = dwLocal["ABAAUFLFD"];
                or1.Parameters.Add("ABAAUFPOS", OracleType.NVarChar).Value = dwLocal["ABAAUFPOS"];

                or1.Parameters.Add("ABASANZSTK", OracleType.NVarChar).Value = dwLocal["ABASANZSTK"];
                or1.Parameters.Add("ABASSTKLG", OracleType.NVarChar).Value = dwLocal["ABASSTKLG"];
                or1.Parameters.Add("ABASSTKLGV", OracleType.NVarChar).Value = dwLocal["ABASSTKLGV"];
                or1.Parameters.Add("ABASSTKLGB", OracleType.NVarChar).Value = dwLocal["ABASSTKLGB"];
                or1.Parameters.Add("ABAAPOS", OracleType.NVarChar).Value = "0001";
                or1.Parameters.Add("ABASGESLG", OracleType.NVarChar).Value = ABASGESLG;
                or1.Parameters.Add("ABASME", OracleType.NVarChar).Value = ABASME;
                or1.Parameters.Add("ABALEAPOS", OracleType.NVarChar).Value = ABALEAPOS;
                or1.Parameters.Add("ABABA", OracleType.NVarChar).Value = BSGKETTART;
                or1.Parameters.Add("ABASGESGEW", OracleType.NVarChar).Value = dwLocal["ABASGESGEW"]; 

                setResult = Connect2Proxy(or1);
                #endregion
                #endregion

                #region============INSERT0002======================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "INSERT INTO ABAUFM(ABAMANDANT, ABAAUFTYP, ABAAUFKRS, ABAAUFLFD, ABAAUFPOS, ABAAPOS, ABAERLKZ, ABARESMG, ABASANZSTK, ABASSTKLG, ABASSTKLGV, ABASSTKLGB, ABASSTKGEW, ABASSTKGEWV, ABASSTKGEWB, ABASSTKBRT, ABASSTKBRTV, ABASSTKBRTB, ABAIANZSTK, ABAIZENSUR1, ABAIZENSURKZ1, ABAIZENSUR2, ABAIZENSURKZ2, ABAIGESLGZS1, ABAIGESLGZS2, ABASTDPOS, ABASFERTKZ, ABAUEBKZ, ABAUMAILKZ, ABASGESLG, ABASGESGEW, ABASME, ABAFRMG, ABARSTSLG, ABARSTSGEW, ABAMINUSLG, ABAMINUSGEW, ABALEAPOS, ABAPOOL, ABARESFLAG, ABAVKAUFTYP, ABAVKAUFKRS, ABAVKAUFLFD, ABAVKAUFPOS, ABAVKUPOS, ABAVB, ABAVG, ABAZUPRIO, ABASTKNEUTR, ABARESPROG, ABARESBEN, ABARESDAT, ABARESZEIT, ABARVSACHB, ABARKUNDNR, ABARBISDAT, ABAVLVB, ABAVLVG, ABAVLSACHB, ABAVLGEGEN, ABAPRKUNDNR, ABAPRAUFKRS, ABAPRAUFLFD, ABAPRAUFPOS, ABAGENEHM, ABAGSACHB, ABALIEFNR, ABAVSACHB, ABAVSTKNR, ABAVERSWEG, ABAMVERSDAT, ABAWVDAT, ABGENDAT, ABAGENNR, ABAGENNAME, ABAGENWEG, ABAZUSTK, ABAZULG, ABAOPTKZ, ABAMAFZST, ABAPART1, ABAPARTST1, ABAPART2, ABAPARTST2, ABAPART3, ABAPARTST3, ABAPART4, ABAPARTST4, ABAPART5, ABAPARTST5, ABAPART6, ABAPARTST6, ABAPART7, ABAPARTST7, ABAPART8, ABAPARTST8, ABAPART9, ABAPARTST9, ABAPART10, ABAPARTST10, ABASZENSUR, ABASZENSURKZ, ABAKUTLSTK, ABABAHNKZ, ABAWDUPOS, ABABAHNEN, ABATEILKZ, ABAKUNDNRU, ABAWERKU, ABAABTU, ABAARTU, ABAVARU, ABADESSU, ABACOLORITU, ABAFARBEU, ABABESCHU, ABAFARBBEZU, ABAANZ1, ABALAENGE1, ABABREITE1, ABAANZ2, ABALAENGE2, ABABREITE2, ABAANZ3, ABALAENGE3, ABABREITE3, ABAANZ4, ABALAENGE4, ABABREITE4, ABAANZ5, ABALAENGE5, ABABREITE5, ABAVERSDAT, ABAVATYP, ABAANZORG, ABAANZKOP, ABAVERSART, ABASPED, ABALIEFKD, ABAVERSKD, ABAADRSLL, ABAVAKZ, ABALIEFKOMP, ABATEILNR, ABAVDPKZ, ABATPMA, ABABOXMAX, ABABOXANZ, ABALGEBNR, ABANKGEB, ABAIFEUCHTE, ABAKUNDNR, ABASTKNR, ABAPARTIE, ABAPARTIEKZ, ABAKDPARTIE, ABAKDAUFTNR, ABAKDAUFDAT, ABAMAART, ABASTKLFDNR, ABAAUFMSL, ABAZUSAM, ABAPACKTYP, ABATAX, ABAHUELSE, ABAWOBST, ABAWICKL, ABAFDRES, ABAKF, ABANRVERG, ABASTKNRKRS, ABASUFFART, ABATRENNZ, ABALAENGEU, ABALAENGES, ABASCHRITW, ABAFUELLZ, ABAASSCHNIT, ABAETITYP, ABAANZRET, ABAKDETKZ, ABADOPPEL, ABALOAN, ABALBAN, ABALPAN, ABAAUFBKZAN, ABALOA2, ABALBA2, ABALPA2, ABAABKZA2, ABAPKL, ABABEM1, ABABEM2, ABAMRKM1, ABAMRKM2, ABAMRKM3, ABAKZNTO, ABAFESP, ABADIAUFKRS, ABADIAUFLFD, ABADIAUFPOS, ABADILG, ABADIGEW, ABADISTK, ABADISLG, ABADISGEW, ABABA, ABAASGESLG, ABAASGESGEW, ABAPNRKRS, ABAPLFDNR, ABAGKREGEL, ABAPROVOR, ABAPRSFE, ABAWSCHTXT, ABAVORSGEL, ABASELVL, ABASELVR, ABAKOLL, ABAVKART, ABAVKFARBE, ABAGBEDKZ, ABADL, ABAKDPARTKZ, ABAFILLER, ABAAENDZL, ABAAENDBEN, ABAAENDDAT, ABANEUBEN, ABANEUDAT)"
                    + "VALUES (:ABAMANDANT, :ABAAUFTYP, :ABAAUFKRS, :ABAAUFLFD, :ABAAUFPOS,'0002', ' ', 0"
                + ", 0, 0, 100, 9999000, 0, 0, 0, 0, 0, 0, 0, ' ', ' ', ' ', ' ', 0, 0, 1, ' ', ' ', ' ', 0, 0, ' ', 0, 0, 0, 0, 0, 0, ' ', ' '"
                + ", ' ', '  ', '      ', '   ', '  ', '   ', '   ', '7', ' ', '        ', '        ', 0, 0, '        ', '        ', 0, '   ', '   ', '        ', ' ', '        '"
                + ", '  ', '      ', '   ', ' ', '        ', '        ', '        ', '            ', '  ', 0, 0, 0, '            ', '                              ', '  ', 0, 0, ' ', 0, '           ', 0, '           ', 0, '           ', 0"
                + ", '           ', 0, '           ', 0, '           ', 0, '           ', 0, '           ', 0, '           ', 0, '           ', 0, ' ', ' ', 0, ' ', 1, 0, ' ', '        ', '   ', '   ', '                    ', '   ', '          ', '          '"
                + ", '          ', '          ', '                    ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '  ', 0, 0, '   ', '   ', '        ', '        ', '        ', ' ', ' ', 0, ' ', '    ', 0, 0, '        ', '  ', 0, '00000000'"
                + ", '            ', '0000000', ' ', '          ', '                    ', 0, ' ', 0, '  ', '  ', '    ', '   ', '      ', 'I', ' ', ' ', ' ', ' ', '  ', ' ', ' ', 0, 0, 0, ' ', ' ', '  ', 0, ' ', '          ', '  ', '  ', '        ', ' ', '  ', '  ', '        ', ' '"
                + ", '  ', '                                                            ', '                                                            ', '    ', '    ', '    ', ' ', ' ', '  ', '000000', '000', 0, 0, 0, 0, 0, '      ', 0, 0, '  ', '000000'"
                + ", '00000000', '        ', 0, '   ', ' ', 0, 0, '     ', '                        ', '          ', ' ', ' ', ' ', '                                                                                    ', 0, '        ', 0"
                + ", :ABANEUBEN, :ABANEUDAT)";
                or1.Parameters.Add("ABAMANDANT", OracleType.NVarChar).Value = dwLocal["ABAMANDANT"];
                or1.Parameters.Add("ABAAUFTYP", OracleType.NVarChar).Value = dwLocal["ABAAUFTYP"];
                or1.Parameters.Add("ABAAUFKRS", OracleType.NVarChar).Value = dwLocal["ABAAUFKRS"];
                or1.Parameters.Add("ABAAUFLFD", OracleType.NVarChar).Value = dwLocal["ABAAUFLFD"];
                or1.Parameters.Add("ABAAUFPOS", OracleType.NVarChar).Value = dwLocal["ABAAUFPOS"];
                or1.Parameters.Add("ABANEUBEN", OracleType.NVarChar).Value = dwLocal["ABANEUBEN"];
                or1.Parameters.Add("ABANEUDAT", OracleType.NVarChar).Value = dwLocal["ABANEUDAT"];
                setResult = Connect2Proxy(or1);


                #region============UPDATE0002======================

                //ABASANZSTK=18	ABASSTKLG=120000
                //ABAVKAUFTYP=K	ABAVKAUFKRS=10	ABAVKAUFLFD=2010	ABAVKAUFPOS=4	ABAVKUPOS=1	ABAVB=119
                //ABARVSACHB=FZ10	ABARKUNDNR=3033
                //ABAVLVB=119 ABAVLSACHB=FZ10
                //ABAPRKUNDNR=3033	ABAPRAUFKRS=10	ABAPRAUFLFD=2010	ABAPRAUFPOS=4
                //ABAVERSDAT=20110923 


                dwLocal["ABAVKAUFTYP"] = "V";
                dwLocal["ABAVKAUFKRS"] = dwBAAUF["BAAUFKRS"];
                dwLocal["ABAVKAUFLFD"] = dwBAAUF["BAAUFLFD"];
                dwLocal["ABAVKAUFPOS"] = dwBAAUF["BAAUFPOS"];
                dwLocal["ABAVKUPOS"] = "01";
                dwLocal["ABAPRAUFKRS"] ="  ";
                dwLocal["ABAPRAUFLFD"] = "000000";
                dwLocal["ABAPRAUFPOS"] ="000";
                dwLocal["ABAVERSDAT"] = dwBAAUF["BADATVON"];
                dwLocal["ABAVAKZ"] = "J";
                dwLocal["ABAWOBST"] = " ";
                

                or1 = OracleDB.CreateCommand();

                or1.CommandText = "UPDATE ABAUFM SET "
                    + "ABASANZSTK=:ABASANZSTK,ABASSTKLG=:ABASSTKLG,ABASSTKLGV=:ABASSTKLGV,ABASSTKLGB=:ABASSTKLGB,ABAVKAUFTYP=:ABAVKAUFTYP,ABAVKAUFKRS=:ABAVKAUFKRS,ABAVKAUFLFD=:ABAVKAUFLFD,ABAVKAUFPOS=:ABAVKAUFPOS "
                    + ",ABAVKUPOS=:ABAVKUPOS,ABAVB=:ABAVB,ABAVLSACHB=:ABAVLSACHB,ABAVAKZ=:ABAVAKZ,ABAWOBST=:ABAWOBST"
                //+",ABAPRKUNDNR=:ABAPRKUNDNR
                +",ABAPRAUFKRS=:ABAPRAUFKRS,ABAPRAUFLFD=:ABAPRAUFLFD,ABAPRAUFPOS=:ABAPRAUFPOS"
                //+",ABAVERSDAT=:ABAVERSDAT"
                + " WHERE ABAMANDANT=:ABAMANDANT AND ABAAUFTYP=:ABAAUFTYP AND ABAAUFKRS=:ABAAUFKRS AND ABAAUFLFD=:ABAAUFLFD AND ABAAUFPOS=:ABAAUFPOS AND ABAAPOS=:ABAAPOS";
                or1.Parameters.Add("ABAMANDANT", OracleType.NVarChar).Value = dwLocal["ABAMANDANT"];
                or1.Parameters.Add("ABAAUFTYP", OracleType.NVarChar).Value = dwLocal["ABAAUFTYP"];
                or1.Parameters.Add("ABAAUFKRS", OracleType.NVarChar).Value = dwLocal["ABAAUFKRS"];
                or1.Parameters.Add("ABAAUFLFD", OracleType.NVarChar).Value = dwLocal["ABAAUFLFD"];
                or1.Parameters.Add("ABAAUFPOS", OracleType.NVarChar).Value = dwLocal["ABAAUFPOS"];
                or1.Parameters.Add("ABAAPOS", OracleType.NVarChar).Value = "0002";
                or1.Parameters.Add("ABASANZSTK", OracleType.NVarChar).Value = dwLocal["ABASANZSTK"];
                or1.Parameters.Add("ABASSTKLG", OracleType.NVarChar).Value = dwLocal["ABASSTKLG"];
                or1.Parameters.Add("ABASSTKLGV", OracleType.NVarChar).Value = dwLocal["ABASSTKLGV"];
                or1.Parameters.Add("ABASSTKLGB", OracleType.NVarChar).Value = dwLocal["ABASSTKLGB"];                	

                or1.Parameters.Add("ABAVKAUFTYP", OracleType.NVarChar).Value = dwLocal["ABAVKAUFTYP"];
                or1.Parameters.Add("ABAVKAUFKRS", OracleType.NVarChar).Value = dwLocal["ABAVKAUFKRS"];
                or1.Parameters.Add("ABAVKAUFLFD", OracleType.NVarChar).Value = dwLocal["ABAVKAUFLFD"];
                or1.Parameters.Add("ABAVKAUFPOS", OracleType.NVarChar).Value = dwLocal["ABAVKAUFPOS"];
                or1.Parameters.Add("ABAVKUPOS", OracleType.NVarChar).Value = dwLocal["ABAVKUPOS"];
                or1.Parameters.Add("ABAVB", OracleType.NVarChar).Value = dwLocal["ABAVB"];
                or1.Parameters.Add("ABAVLSACHB", OracleType.NVarChar).Value = dwLocal["ABAVLSACHB"];
                or1.Parameters.Add("ABAVAKZ", OracleType.NVarChar).Value = dwLocal["ABAVAKZ"];
                or1.Parameters.Add("ABAWOBST", OracleType.NVarChar).Value = dwLocal["ABAWOBST"]; 
          //      or1.Parameters.Add("ABAPRKUNDNR", OracleType.NVarChar).Value = dwLocal["ABAPRKUNDNR"];
                or1.Parameters.Add("ABAPRAUFKRS", OracleType.NVarChar).Value = dwLocal["ABAPRAUFKRS"];
                or1.Parameters.Add("ABAPRAUFLFD", OracleType.NVarChar).Value = dwLocal["ABAPRAUFLFD"];
                or1.Parameters.Add("ABAPRAUFPOS", OracleType.NVarChar).Value = dwLocal["ABAPRAUFPOS"];
                //or1.Parameters.Add("ABAVERSDAT", OracleType.NVarChar).Value = dwLocal["ABAVERSDAT"];

                setResult = Connect2Proxy(or1);
                #endregion
                #endregion

                #region============SELECT==========================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM ABAUFM "
                + " WHERE ABAMANDANT=:ABAMANDANT AND ABAAUFKRS=:ABAAUFKRS AND ABAAUFLFD= :ABAAUFLFD AND ABAAUFPOS= :ABAAUFPOS";

                or1.Parameters.Add("ABAMANDANT", OracleType.NVarChar).Value = dwLocal["ABAMANDANT"];
                or1.Parameters.Add("ABAAUFKRS", OracleType.NVarChar).Value = dwLocal["ABAAUFKRS"];
                or1.Parameters.Add("ABAAUFLFD", OracleType.NVarChar).Value = dwLocal["ABAAUFLFD"];
                or1.Parameters.Add("ABAAUFPOS", OracleType.NVarChar).Value = dwLocal["ABAAUFPOS"];
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "ABAUFM";
                }
                setReturn.Merge(setResult);
                #endregion
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public virtual DataSet InsertGAAUF(DataRow dwABPOS, string DISPONUM)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            OracleCommand or1;
            DataRow dwLocal = null, dwBASTGA = null, dwGSDAT = null;
            try
            {
                //SELECT * FROM WDECK WHERE WDAUFKRS='T6'AND WDAUFLFD='005116'AND WDAUFPOS='010'
                #region============GETYARNDATA=======================
                string  ART = "",  VAR = "",  FARBE = "";
                ART = dwABPOS["ABPART"].ToString();
                VAR = dwABPOS["ABPVAR"].ToString();
                FARBE = dwABPOS["ABPFARBE"].ToString();
                setResult = GetBASTGA(ART, VAR, FARBE);
                setReturn.Merge(setResult);
                DataRow dwGSCOLOR;
                double meterpkg = 0;
                foreach (DataRow dwTemp in setResult.Tables["BASTGA"].Rows)
                {
                    dwBASTGA = dwTemp;

                    dwGSCOLOR = setINTEX.GSCOLOR.NewGSCOLORRow();
                    dwGSCOLOR["GSCMANDANT"] = dwBASTGA["BAGMANDANT"];
                    dwGSCOLOR["GSCART"] = dwBASTGA["BAGGART"];
                    dwGSCOLOR["GSCVAR"] = dwBASTGA["BAGGVAR"];
                    dwGSCOLOR["GSCFARBE"] = dwBASTGA["BAGGFARBE"];
                    YarnMasterData m_YD = new YarnMasterData(OracleDB, proxy);
                    setResult = new DataSet();
                    setResult = m_YD.BuildYarnMasterData(setResult, dwGSCOLOR);
                    setReturn.Merge(setResult);
                    foreach (DataRow dwTemp1 in setResult.Tables["GSDAT"].Rows)
                    {
                        dwGSDAT = dwTemp1;
                    }
                    meterpkg = MTR1KG(System.Convert.ToDouble(dwGSDAT["GSRECHNR"].ToString()) * 0.0001, dwGSDAT["GSRECHNUM"].ToString());
                #endregion

                    #region============MAPDATA=========================
                    dwLocal = setINTEX.GAAUF.NewGAAUFRow();
                    dwLocal["GAMANDANT"] = dwABPOS["ABPMANDANT"];
                    dwLocal["GAAUFKRS"] = dwABPOS["ABPAUFKRS"];
                    dwLocal["GAAUFLFD"] = dwABPOS["ABPAUFLFD"];
                    dwLocal["GAAUFPOS"] = dwABPOS["ABPAUFPOS"];
                    dwLocal["GANEUBEN"] = dwABPOS["ABPNEUBEN"];
                    dwLocal["GANEUDAT"] = dwABPOS["ABPNEUDAT"];
                    dwLocal["GABEM"] = Left(DISPONUM + "                                                                    ", 40);
                    #endregion

                    #region============INSERT==========================
                    or1 = OracleDB.CreateCommand();
                    dwLocal["GAPOS"] = dwBASTGA["BAGPOS"];
                    or1.CommandText = "INSERT INTO GAAUF(GAMANDANT, GAAUFKRS, GAAUFLFD, GAAUFPOS, GASA, GAPOS, GAAENDZL, GAAENDBEN, GAAENDDAT, GANEUBEN, GANEUDAT, GADATVON, GADATBIS, GADATVON1, GADATBIS1, GAART, GAVAR, GAFARBE, GAURVAR, GADEZI, GAKG1, GASP1, GAKA1, GAKG2, GASP2, GAKA2, GAKG3, GASP3, GAKA3, GAKG4, GASP4, GAKA4, GAKG5, GASP5, GAKA5, GAKG6, GASP6, GAKA6, GAKG7, GASP7, GAKA7, GAABF, GAERLKZ, GADISPOKZ, GALO, GALB, GALP, GAAUFBKZ, GABEM, GAVPEINH, GAHUELSE, GAANZBAUM, GASPUL, GALAENGE, GASPULGEW, GAAG, GAPRODV, GAAUFMSL, GAKF, GAFDRES, GAWICKL, GASACHB, GAANLO, GAANLB, GAANLP, GAANAUFBKZ, GALIEFSCH, GAFREIDAT, GAFREIBEN, GALIEFNR, GAMATKOMPDR, GAFUSSTEXT, GAAFOLGE, GAAUFTRKZ, GABDEKZ, GABASMG2, GABRUTTOKZ, GAERSATZ, GAURSA, GAURPOS, GATLSA, GATLPOS, GAINFOKZ, GADECKUNG, GAUSERZK, GAVARKZ, GAZUKOMP, GAAFDLGS, GAAFDLGSZ, GAGESFDZ, GABEDFDZ, GAZLLG, GAABF2, GAZBEDKG, GAFILLER)"
                        + "VALUES (:GAMANDANT, :GAAUFKRS, :GAAUFLFD, :GAAUFPOS, '723', :GAPOS, 1, '        ', '00000000', :GANEUBEN, :GANEUDAT, 0, 0, '        ', '        '"
                        + ", '                    ', '   ', '          ', '   ', ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ' ', 'B', 'EX', 'WV', '010101  ', ' ', :GABEM, '    ', '      ', '00', 1, 6430499, 0, '  ', '  ', '  ', ' ', ' ', ' ', '        ', '  ', '  ', '        ', ' ', '        ', 0, '        ', '        ', ' ', '   ', '050', 'K', ' ', 3841, ' ', ' ', '   ', '00', '   ', '00', ' ', ' ', '        ', ' ', ' ', 0, 0, 0, 0, 0, 0, 0, '                                         ')";
                    or1.Parameters.Add("GAMANDANT", OracleType.NVarChar).Value = dwLocal["GAMANDANT"];
                    or1.Parameters.Add("GAAUFKRS", OracleType.NVarChar).Value = dwLocal["GAAUFKRS"];
                    or1.Parameters.Add("GAAUFLFD", OracleType.NVarChar).Value = dwLocal["GAAUFLFD"];
                    or1.Parameters.Add("GAAUFPOS", OracleType.NVarChar).Value = dwLocal["GAAUFPOS"];
                    or1.Parameters.Add("GAPOS", OracleType.NVarChar).Value = dwLocal["GAPOS"];
                    or1.Parameters.Add("GABEM", OracleType.NVarChar).Value = dwLocal["GABEM"];
                    or1.Parameters.Add("GANEUBEN", OracleType.NVarChar).Value = dwLocal["GANEUBEN"];
                    or1.Parameters.Add("GANEUDAT", OracleType.NVarChar).Value = dwLocal["GANEUDAT"];


                    setResult = Connect2Proxy(or1);
                    dwLocal["GADATVON"] = dwABPOS["ABPSTARTDAT"];
                    dwLocal["GADATBIS"] = dwABPOS["ABPSTARTDAT"];
                    dwLocal["GAART"] = dwBASTGA["BAGGART"];
                    dwLocal["GAVAR"] = dwBASTGA["BAGGVAR"];
                    dwLocal["GAFARBE"] = dwBASTGA["BAGGFARBE"];
                    long ABPSOLLMENGE8 = System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE8"]);
                    long GL = System.Convert.ToInt64(dwABPOS["ABPSOLLMENGE1"]);
                    long RT = System.Convert.ToInt64(dwBASTGA["BAGKGBRUT"]);
                    long GAKG1 = System.Convert.ToInt64(System.Math.Round(GL * 0.01 * RT * 0.001 * 0.1 * ABPSOLLMENGE8*0.01, 0));
                    long GABASMG2 = System.Convert.ToInt64(System.Math.Round(GL * RT * 0.001, 0));
                     
                    dwLocal["GAKG1"] = GAKG1;
                    dwLocal["GABASMG2"] = dwBASTGA["BAGKGNET"];
                    dwLocal["GALO"] = "01";
                    dwLocal["GALB"] = "WV";
                    dwLocal["GALP"] = "999999";
                    dwLocal["GADISPOKZ"] = dwBASTGA["BAGDISPOKZ"];
                    dwLocal["GASPUL"] = 1;
                    dwLocal["GALAENGE"] = 100000;// System.Math.Round(meterpkg * GAKG1, 0);
                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = "UPDATE GAAUF SET GADATVON=:GADATVON "
                        + ",GADATBIS=:GADATBIS,GAART=:GAART,GAVAR=:GAVAR,GAFARBE=:GAFARBE,GAKG1=:GAKG1"
                        + ",GABASMG2=:GABASMG2,GALO=:GALO,GALB=:GALB,GALP=:GALP,GADISPOKZ=:GADISPOKZ"
                        + ",GASPUL=:GASPUL,GALAENGE=:GALAENGE"
                        + " WHERE GAMANDANT=:GAMANDANT AND GAAUFKRS=:GAAUFKRS AND GAAUFLFD=:GAAUFLFD AND GAAUFPOS=:GAAUFPOS AND GAPOS=:GAPOS";

                    or1.Parameters.Add("GAMANDANT", OracleType.NVarChar).Value = dwLocal["GAMANDANT"];
                    or1.Parameters.Add("GAAUFKRS", OracleType.NVarChar).Value = dwLocal["GAAUFKRS"];
                    or1.Parameters.Add("GAAUFLFD", OracleType.NVarChar).Value = dwLocal["GAAUFLFD"];
                    or1.Parameters.Add("GAAUFPOS", OracleType.NVarChar).Value = dwLocal["GAAUFPOS"];
                    or1.Parameters.Add("GAPOS", OracleType.NVarChar).Value = dwLocal["GAPOS"];

                    or1.Parameters.Add("GADATVON", OracleType.NVarChar).Value = dwLocal["GADATVON"];
                    or1.Parameters.Add("GADATBIS", OracleType.NVarChar).Value = dwLocal["GADATBIS"];
                    or1.Parameters.Add("GAART", OracleType.NVarChar).Value = dwLocal["GAART"];
                    or1.Parameters.Add("GAVAR", OracleType.NVarChar).Value = dwLocal["GAVAR"];
                    or1.Parameters.Add("GAFARBE", OracleType.NVarChar).Value = dwLocal["GAFARBE"];
                    or1.Parameters.Add("GAKG1", OracleType.NVarChar).Value = dwLocal["GAKG1"];
                    or1.Parameters.Add("GABASMG2", OracleType.NVarChar).Value = dwLocal["GABASMG2"];
                    or1.Parameters.Add("GALO", OracleType.NVarChar).Value = dwLocal["GALO"];
                    or1.Parameters.Add("GALB", OracleType.NVarChar).Value = dwLocal["GALB"];
                    or1.Parameters.Add("GALP", OracleType.NVarChar).Value = dwLocal["GALP"];
                    or1.Parameters.Add("GADISPOKZ", OracleType.NVarChar).Value = dwLocal["GADISPOKZ"];
                    
                    or1.Parameters.Add("GASPUL", OracleType.NVarChar).Value = dwLocal["GASPUL"];
                    or1.Parameters.Add("GALAENGE", OracleType.NVarChar).Value = dwLocal["GALAENGE"];
                    setResult = Connect2Proxy(or1);
                    #endregion
                }

                #region============SELECT==========================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM GAAUF "
                + " WHERE GAMANDANT=:GAMANDANT AND GAAUFKRS=:GAAUFKRS AND GAAUFLFD=:GAAUFLFD AND GAAUFPOS=:GAAUFPOS";
                or1.Parameters.Add("GAMANDANT", OracleType.NVarChar).Value = dwLocal["GAMANDANT"];
                or1.Parameters.Add("GAAUFKRS", OracleType.NVarChar).Value = dwLocal["GAAUFKRS"];
                or1.Parameters.Add("GAAUFLFD", OracleType.NVarChar).Value = dwLocal["GAAUFLFD"];
                or1.Parameters.Add("GAAUFPOS", OracleType.NVarChar).Value = dwLocal["GAAUFPOS"];
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "GAAUF";
                }
                setReturn.Merge(setResult);
                #endregion

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public virtual DataSet InsertBABST(DataRow dwABPOS, DataRow dwBAAUF,DataRow dwBSGROE,DataRow dwBSSATZ,DataRow dwBHSATZ)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            OracleCommand or1;
            string LFD = "000000";
            string KRS = "SZ";
            DataRow dwLocal=null;
            try
            { 
                #region============MAPDATA=========================
                double BAANZ1=1;
                double BAMTR1=0.0,BMSOLLLG,BMSOLLGEW; 
                BAMTR1 = System.Math.Round(System.Convert.ToDouble(dwABPOS["ABPSOLLMENGE1"].ToString()) * 0.01, 0)*10;
                BAANZ1 = System.Math.Round(System.Convert.ToDouble(dwABPOS["ABPSOLLMENGE8"].ToString()) * 0.01, 0);

                BMSOLLLG=System.Math.Round(BAMTR1/BAANZ1,0);
                double BHKGNET = System.Convert.ToDouble(dwBHSATZ["BHKGNET"].ToString());
                double BSFAKTOR = System.Convert.ToDouble(dwBSSATZ["BSFAKTOR"].ToString());
                BMSOLLGEW = System.Math.Round(System.Convert.ToDouble(dwABPOS["ABPSOLLMENGE5"].ToString()) *10/ BAANZ1, 0);  
                dwLocal = setINTEX.BABST.NewBABSTRow();
                for (int bi = 0; bi < BAANZ1; bi++)
                {
                    LFD = GetAUFLFD(KRS, "BABST");
                    dwLocal["BMMANDANT"] = dwABPOS["ABPMANDANT"];
                    dwLocal["BMBAUMKRS"] = KRS;
                    dwLocal["BMBAUMLFD"] = LFD;
                    dwLocal["BMKART"] = dwABPOS["ABPART"];
                    dwLocal["BMKVAR"] = dwABPOS["ABPVAR"];
                    dwLocal["BMFARBE"] = dwABPOS["ABPFARBE"];

                    dwLocal["BMAUFKRS"] = dwABPOS["ABPAUFKRS"];
                    dwLocal["BMAUFLFD"] = dwABPOS["ABPAUFLFD"];
                    dwLocal["BMAUFPOS"] = dwABPOS["ABPAUFPOS"];

                    dwLocal["BMNEUBEN"] = dwABPOS["ABPNEUBEN"];
                    dwLocal["BMNEUDAT"] = dwABPOS["ABPNEUDAT"];
                    dwLocal["BMFDZ"] = dwBSSATZ["BSFDZ"];
                    dwLocal["BMKETTTYP"] = dwBSGROE["BSGKETTART"];

                    dwLocal["BMSOLLGEW"] = BMSOLLGEW;
                    dwLocal["BMSOLLLG"] = BMSOLLLG;


                #endregion

                    #region============INSERT R========================
                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = " INSERT INTO BABST(BMMANDANT, BMBAUMKRS, BMBAUMLFD, BMKART, BMKVAR, BMFARBE, BMZENSUR, BMZUSTAND, BMSCHLICHTGR, BMSCHLICHTNR, BMBAUMKZ, BMVERWEN, BMHERART, BMFDZ, BMGABED, BMKETTTYP, BMKANTE, BMLO, BMLB, BMLP, BMAUFBKZ, BMDATERL, BMBEM, BMKOLLINR, BMSPSTA, BMSPGRD, BMORGKZ, BMLEER, BMSOLLKZ, BMSOLLLG, BMSOLLGEW, BMSOLLVLG, BMSOLLSTK, BMISTLG, BMISTGEW, BMISTVLG, BMISTSTK, BMRESTLG, BMURISTLG, BMRESTGEW, BMKGNET, BMKGBRUT, BMTARAI, BMTARAA, BMAUFKRS, BMAUFLFD, BMAUFPOS, BMSA, BMAUFTYP, BMFERTKZ, BMPRODLO, BMPRODLB, BMPRODLP, BMPRODAUFBKZ, BMSPPART, BMPARTIE, BMPARTIEKZ, BMDATVW, BMDATDRU, BMDATABG, BMDATRP, BMDATRPM, BMDATANG, BMDATABWEB, BMERSATZKZ, BMKOMBIKZ, BMANZTB, BMBAHNIG, BMPICKUP, BMABAUMKRS, BMABAUMLFD, BMSTKZL, BMBAABGZ, BMAPOS, BMRAFOLGE, BMAUSFFRB, BMTAX, BMSCHIENE, BMMNRKRS, BMMLFDNR, BMMPOS, BMMAPOS, BMDL, BMBEARB, BMZULO, BMZULB, BMZULP, BMZUAUFBKZ, BMRART, BMRVAR, BMRFARBE, BMLIEFNR, BMBESTKZ, BMBNRLIEF, BMEGKZ, BMLIEFSCHNR, BMLIEFDAT, BMRECHNR, BMKLABR, BMEINPR, BMRECHDAT, BMBDEKZ, BMJJJJBDE, BMBNRBDE, BMDATBDE, BMBDEBKZ, BMJJJJMAT, BMBNRMAT, BMDATMAT, BMISOLLLG, BMIISTLG, BMIDIFFLG, BMIDATUM, BMISTATUS, BMIJJJJ, BMIBELEGNR, BMIBPOSVON, BMIBPOSBIS, BMRODA, BMWIND, BMFILLER, BMAENDZL, BMAENDBEN, BMAENDDAT, BMNEUBEN, BMNEUDAT)"
                        +" VALUES ("
                    + ":BMMANDANT, :BMBAUMKRS, :BMBAUMLFD,:BMKART,:BMKVAR,:BMFARBE, ' ', '    ', '     ', '000000000000000', 'Z', 'P', 'S'"
                    + ", :BMFDZ, 'J',:BMKETTTYP, '  ', '  ', '  ', '        ', ' ', 0, '                                        ', '        ', '  ', '  ', 'J', ' ', 'J', :BMSOLLLG, :BMSOLLGEW, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0"
                    + ",:BMAUFKRS,:BMAUFLFD, :BMAUFPOS, '320', 'V', 'E', '01', 'WV', '999999  ', ' ', '          ', '0000000', '0', 0, 0, 0, 0, 0, 0, 0, ' ', ' ', 0, 0, 0"
                    +", '  ', '000000', 0, ' ', '0001', '000', 0, '   ', '     ', 'SI', '3000', '01', '00', ' ', '        ', '  ', '  ', '        ', ' ', '                    ', '  ', '          ', '        ', ' ', '          ', ' ', '        ', 0, '          '"
                    + ", ' ', 0, 0, '0', 0, 0, '0000000000', ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0, '  000000                                                                      ', 0, '        ', 0, :BMNEUBEN, :BMNEUDAT)";
                    or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = dwLocal["BMMANDANT"];
                    or1.Parameters.Add("BMBAUMKRS", OracleType.NVarChar).Value = dwLocal["BMBAUMKRS"];
                    or1.Parameters.Add("BMBAUMLFD", OracleType.NVarChar).Value = dwLocal["BMBAUMLFD"];
                    or1.Parameters.Add("BMAUFKRS", OracleType.NVarChar).Value = dwLocal["BMAUFKRS"];
                    or1.Parameters.Add("BMAUFLFD", OracleType.NVarChar).Value = dwLocal["BMAUFLFD"];
                    or1.Parameters.Add("BMAUFPOS", OracleType.NVarChar).Value = dwLocal["BMAUFPOS"];
                    or1.Parameters.Add("BMFDZ", OracleType.NVarChar).Value = dwLocal["BMFDZ"];
                    or1.Parameters.Add("BMKETTTYP", OracleType.NVarChar).Value = dwLocal["BMKETTTYP"];
                    or1.Parameters.Add("BMKART", OracleType.NVarChar).Value = dwLocal["BMKART"];
                    or1.Parameters.Add("BMKVAR", OracleType.NVarChar).Value = dwLocal["BMKVAR"];
                    or1.Parameters.Add("BMFARBE", OracleType.NVarChar).Value = dwLocal["BMFARBE"]; 

                    or1.Parameters.Add("BMSOLLLG", OracleType.NVarChar).Value = dwLocal["BMSOLLLG"];
                    or1.Parameters.Add("BMSOLLGEW", OracleType.NVarChar).Value = dwLocal["BMSOLLGEW"];

                    or1.Parameters.Add("BMNEUBEN", OracleType.NVarChar).Value = dwLocal["BMNEUBEN"];
                    or1.Parameters.Add("BMNEUDAT", OracleType.NVarChar).Value = dwLocal["BMNEUDAT"];
                    setResult = Connect2Proxy(or1);
                    /*
                  or1.CommandText = "INSERT INTO BABST(BMMANDANT, BMBAUMKRS, BMBAUMLFD, BMKART, BMKVAR, BMFARBE, BMZENSUR, BMZUSTAND, BMSCHLICHTGR, BMSCHLICHTNR, BMBAUMKZ, BMVERWEN, BMHERART, BMFDZ, BMGABED, BMKETTTYP, BMKANTE, BMLO, BMLB, BMLP, BMAUFBKZ, BMDATERL, BMBEM, BMKOLLINR, BMSPSTA, BMSPGRD, BMORGKZ, BMLEER, BMSOLLKZ, BMSOLLLG, BMSOLLGEW, BMSOLLVLG, BMSOLLSTK, BMISTLG, BMISTGEW, BMISTVLG, BMISTSTK, BMRESTLG, BMURISTLG, BMRESTGEW, BMKGNET, BMKGBRUT, BMTARAI, BMTARAA, BMAUFKRS, BMAUFLFD, BMAUFPOS, BMSA, BMAUFTYP, BMFERTKZ, BMPRODLO, BMPRODLB, BMPRODLP, BMPRODAUFBKZ, BMSPPART, BMPARTIE, BMPARTIEKZ, BMDATVW, BMDATDRU, BMDATABG, BMDATRP, BMDATRPM, BMDATANG, BMDATABWEB, BMERSATZKZ, BMKOMBIKZ, BMANZTB, BMBAHNIG, BMPICKUP, BMABAUMKRS, BMABAUMLFD, BMSTKZL, BMBAABGZ, BMAPOS, BMRAFOLGE, BMAUSFFRB, BMTAX, BMSCHIENE, BMMNRKRS, BMMLFDNR, BMMPOS, BMMAPOS, BMDL, BMBEARB, BMZULO, BMZULB, BMZULP, BMZUAUFBKZ, BMRART, BMRVAR, BMRFARBE, BMLIEFNR, BMBESTKZ, BMBNRLIEF, BMEGKZ, BMLIEFSCHNR, BMLIEFDAT, BMRECHNR, BMKLABR, BMEINPR, BMRECHDAT, BMBDEKZ, BMJJJJBDE, BMBNRBDE, BMDATBDE, BMBDEBKZ, BMJJJJMAT, BMBNRMAT, BMDATMAT, BMISOLLLG, BMIISTLG, BMIDIFFLG, BMIDATUM, BMISTATUS, BMIJJJJ, BMIBELEGNR, BMIBPOSVON, BMIBPOSBIS, BMRODA, BMWIND, BMFILLER, BMAENDZL, BMAENDBEN, BMAENDDAT, BMNEUBEN, BMNEUDAT)"
                      + " VALUES (:BMMANDANT, :BMBAUMKRS, :BMBAUMLFD, :BMKART, :BMKVAR, :BMFARBE, '1', '    ', '     ', '000000000000000', 'Z', 'P', 'S'"
                  +", :BMFDZ, 'J', :BMKETTTYP"
                  + ", '  ', '  ', '  ', '        '"
                  + ", ' ', 0, '                                        ', '        ', '  ', '  ', 'J', 'J', ' ', :BMSOLLLG, :BMSOLLGEW, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0"
                  + ", :BMAUFKRS, :BMAUFLFD, :BMAUFPOS, '320', 'V', 'E', '01', 'WV, '999999', ' ', '          ', '       ', '0', 0, 0, 0, 0, 0, 0, 0, ' ', ' ', 0, 0, 0, '  ', '000000', 0, ' ', '0001', '000'"
                  + ", 0, '   ', '     ', '  ', '0000', '00', '00', ' ', '        ', '  ', '  ', '        ', ' ', '                    ', '  ', '          ', '        ', ' ', '          ', ' ', '        ', 0, '          ', ' ', 0, 0, '1', 0, 0, '0000000000'"
                  + ", '0', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0, '                                                                              ', 0, '        ', 0,:BMNEUBEN, :BMNEUDAT)";

     

                 
                  */
                }
                #endregion

                #region============SELECT==========================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM BABST "
                + " WHERE BMMANDANT=:BMMANDANT AND BMAUFKRS=:BMAUFKRS AND BMAUFLFD=:BMAUFLFD AND BMAUFPOS=:BMAUFPOS";
                or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = dwLocal["BAMANDANT"];
                or1.Parameters.Add("BMAUFKRS", OracleType.NVarChar).Value = dwLocal["BMAUFKRS"];
                or1.Parameters.Add("BMAUFLFD", OracleType.NVarChar).Value = dwLocal["BMAUFLFD"];
                or1.Parameters.Add("BMAUFPOS", OracleType.NVarChar).Value = dwLocal["BMAUFPOS"];
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "BABST";
                }
                setReturn.Merge(setResult);
                #endregion

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }

        public virtual DataSet InsertBAAUF(DataRow dwABPOS)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            OracleCommand or1;
            DataRow dwLocal, dwWASTKE = null, dwBSGROE = null;
            try
            {
                //SELECT * FROM WDECK WHERE WDAUFKRS='T6'AND WDAUFLFD='005116'AND WDAUFPOS='010'
                #region============GETBEAMDATA=======================
                DataRow dwBSFARB = setINTEX.BSFARB.NewBSFARBRow();
                dwBSFARB["BSFMANDANT"] = dwABPOS["ABPMANDANT"];
                dwBSFARB["BSFKART"] = dwABPOS["ABPART"];
                dwBSFARB["BSFKVAR"] = dwABPOS["ABPVAR"];
                dwBSFARB["BSFKFARBE"] = dwABPOS["ABPFARBE"];
                WarpMasterData m_WD = new WarpMasterData(OracleDB, proxy);
                setResult = m_WD.GetData(dwBSFARB);
                setReturn.Merge(setResult);
                foreach (DataRow dwTemp in setResult.Tables["BSGROE"].Rows)
                {
                    dwBSGROE = dwTemp;
                }
                if (dwBSGROE == null)
                {
                    EventDispatcher.Instance.RaiseStatus("没有轴信息BSGROE", StatusEventType.StopProgress);
                    return setReturn;
                }
                #endregion

                #region============MAPDATA=========================
                dwLocal = setINTEX.BAAUF.NewBAAUFRow();
                dwLocal["BAMANDANT"] = dwABPOS["ABPMANDANT"];
                dwLocal["BAAUFKRS"] = dwABPOS["ABPAUFKRS"];
                dwLocal["BAAUFLFD"] = dwABPOS["ABPAUFLFD"];
                dwLocal["BAAUFPOS"] = dwABPOS["ABPAUFPOS"];
                		


                dwLocal["BANEUBEN"] = dwABPOS["ABPNEUBEN"];
                dwLocal["BANEUDAT"] = dwABPOS["ABPNEUDAT"];
                #endregion

                #region============INSERT R========================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "INSERT INTO BAAUF(BAMANDANT, BAAUFTYP, BAAUFKRS, BAAUFLFD, BAAUFPOS, BASA, BAPOS, BAAFOLGE, BADATVON, BADATBIS, BAKART, BAKVAR, BAKFARBE, BAMTR1, BAANZ1, BAMTR2, BAANZ2, BAMTR3, BAANZ3, BAMTR4, BAANZ4, BAMTR5, BAANZ5, BAMTR6, BAANZ6, BAMTR7, BAANZ7, BAERLKZ, BABAUMART, BADRKZ, BADISPOKZ, BALO, BALB, BALP, BAAUFBKZ, BAURKVAR, BAAENDZL, BAAENDBEN, BAAENDDAT, BANEUBEN, BANEUDAT, BADOMKZ, BABASMG, BALLEIST, BARLEIST, BASCHIENE, BATLPOS, BAINFOKZ, BAVARKZ, BATLSA, BAABF2, BAZBEDKG, BAZBEDMTR, BAFILLER)"
                    + "VALUES (:BAMANDANT, 'V', :BAAUFKRS, :BAAUFLFD, :BAAUFPOS, '320', '0000', '020', 0, 0, '                    ', '  ', '          ', 32400, 1, 0, 0, 0"
                + ", 0, 0, 0, 0, 0, 0, 0, 0, 0, ' ', '      ', '0', ' ', 'EX', 'WV', '010101  ', ' ', '  ', 1, '        ', 0,:BANEUBEN, :BANEUDAT, ' ', 12000, '    ', '    ', '     ', '00', ' ', ' ', '   ', 0, 0, 0, '                                                 ')";
                or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwLocal["BAMANDANT"];
                or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwLocal["BAAUFKRS"];
                or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = dwLocal["BAAUFLFD"];
                or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = dwLocal["BAAUFPOS"];
                or1.Parameters.Add("BANEUBEN", OracleType.NVarChar).Value = dwLocal["BANEUBEN"];
                or1.Parameters.Add("BANEUDAT", OracleType.NVarChar).Value = dwLocal["BANEUDAT"];

                setResult = Connect2Proxy(or1);
                dwLocal["BADATVON"] = dwABPOS["ABPSTARTDAT"];
                dwLocal["BADATBIS"] = dwABPOS["ABPSTARTDAT"];
                dwLocal["BAKART"] = dwABPOS["ABPART"];
                dwLocal["BAKVAR"] = dwABPOS["ABPVAR"];
                dwLocal["BAKFARBE"] = dwABPOS["ABPFARBE"];

                dwLocal["BAMTR1"] = System.Math.Round(System.Convert.ToDouble(dwABPOS["ABPSOLLMENGE1"].ToString()) * 0.1, 0);
                dwLocal["BAANZ1"] =System.Math.Round( System.Convert.ToDouble(dwABPOS["ABPSOLLMENGE8"].ToString())*0.01,0);
                dwLocal["BAMTR2"] = dwLocal["BAMTR1"];
                dwLocal["BAANZ2"] = dwLocal["BAANZ1"];
             
                dwLocal["BABAUMART"] = dwBSGROE["BSGKETTART"];
                dwLocal["BALO"] = "01";
                dwLocal["BALB"] = "WV";
                dwLocal["BALP"] = "999999";
                dwLocal["BABASMG"] =0;
                 
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "UPDATE BAAUF SET BADATVON=:BADATVON "
                    + ",BADATBIS=:BADATBIS,BAKART=:BAKART,BAKVAR=:BAKVAR,BAKFARBE=:BAKFARBE"
                    //+ ",BABAUMART=:BABAUMART"
                +",BALO=:BALO,BALB=:BALB,BALP=:BALP"
                //+",BADISPOKZ=:BADISPOKZ,BALLEIST=:BALLEIST,BARLEIST=:BARLEIST,BADOMKZ=:BADOMKZ"
                    +",BABASMG=:BABASMG"
                    + ",BAMTR1=:BAMTR1,BAANZ1=:BAANZ1,BAMTR2=:BAMTR2,BAANZ2=:BAANZ2"
                    + " WHERE BAMANDANT=:BAMANDANT AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD AND BAAUFPOS=:BAAUFPOS";

                or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwLocal["BAMANDANT"];

                or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwLocal["BAAUFKRS"];
                or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = dwLocal["BAAUFLFD"];
                or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = dwLocal["BAAUFPOS"];

                or1.Parameters.Add("BADATVON", OracleType.NVarChar).Value = dwLocal["BADATVON"];
                or1.Parameters.Add("BADATBIS", OracleType.NVarChar).Value = dwLocal["BADATBIS"];
                or1.Parameters.Add("BAKART", OracleType.NVarChar).Value = dwLocal["BAKART"];
                or1.Parameters.Add("BAKVAR", OracleType.NVarChar).Value = dwLocal["BAKVAR"];
                or1.Parameters.Add("BAKFARBE", OracleType.NVarChar).Value = dwLocal["BAKFARBE"];
                or1.Parameters.Add("BAMTR1", OracleType.NVarChar).Value = dwLocal["BAMTR1"];
                or1.Parameters.Add("BAANZ1", OracleType.NVarChar).Value = dwLocal["BAANZ1"];
                or1.Parameters.Add("BAMTR2", OracleType.NVarChar).Value = dwLocal["BAMTR2"];
                or1.Parameters.Add("BAANZ2", OracleType.NVarChar).Value = dwLocal["BAANZ2"];
                //or1.Parameters.Add("BABAUMART", OracleType.NVarChar).Value = dwLocal["BABAUMART"];
                or1.Parameters.Add("BALO", OracleType.NVarChar).Value = dwLocal["BALO"];
                or1.Parameters.Add("BALB", OracleType.NVarChar).Value = dwLocal["BALB"];
                or1.Parameters.Add("BALP", OracleType.NVarChar).Value = dwLocal["BALP"];
                or1.Parameters.Add("BABASMG", OracleType.NVarChar).Value = dwLocal["BABASMG"];
                /*
                or1.Parameters.Add("BADISPOKZ", OracleType.NVarChar).Value = dwLocal["BADISPOKZ"];
                or1.Parameters.Add("BALLEIST", OracleType.NVarChar).Value = dwLocal["BALLEIST"];
                or1.Parameters.Add("BARLEIST", OracleType.NVarChar).Value = dwLocal["BARLEIST"];
                or1.Parameters.Add("BADOMKZ", OracleType.NVarChar).Value = dwLocal["BADOMKZ"];
                */ 
                setResult = Connect2Proxy(or1);
                #endregion

                #region============SELECT==========================
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM BAAUF "
                + " WHERE BAMANDANT=:BAMANDANT AND BAAUFKRS=:BAAUFKRS AND BAAUFLFD=:BAAUFLFD AND BAAUFPOS=:BAAUFPOS";
                or1.Parameters.Add("BAMANDANT", OracleType.NVarChar).Value = dwLocal["BAMANDANT"];
                or1.Parameters.Add("BAAUFKRS", OracleType.NVarChar).Value = dwLocal["BAAUFKRS"];
                or1.Parameters.Add("BAAUFLFD", OracleType.NVarChar).Value = dwLocal["BAAUFLFD"];
                or1.Parameters.Add("BAAUFPOS", OracleType.NVarChar).Value = dwLocal["BAAUFPOS"];
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "BAAUF";
                }
                setReturn.Merge(setResult);
                #endregion

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public virtual DataSet GetABPOS(DataRow dwBAAUF, DataSet setInput,DataRow dwAB55, DataRow dwDispo,DataRow dwBSGROE,DataRow dwBSSATZ,
            DataRow dwBHSATZ, double ReqQtyMTR, string ABKAUFART,string DISPONUM, double Wnum=100,string KRS = "T4", int LeadTime = 5)
        {
            DataSet setReturn = new DataSet();

            DataSet setResult = new DataSet();
            DataRow dwABPOS = null;
            try
            {
                #region============ABPOS======================
                EventDispatcher.Instance.RaiseStatus("开始创建浆纱ABPOS", StatusEventType.RunningProgress);
                setResult = InsertAB45POS(dwBAAUF, setInput, dwAB55, ReqQtyMTR, ABKAUFART,Wnum, KRS, LeadTime);
                #endregion
                if (setResult.Tables.Contains("ABPOS"))
                {
                    if (setResult.Tables["ABPOS"].Rows.Count > 0)
                    {
                        dwABPOS = setResult.Tables["ABPOS"].Rows[0];
                    }
                } 
                setReturn.Merge(setResult);
                #region============ABKOPF=====================
                EventDispatcher.Instance.RaiseStatus("开始创建浆纱ABKOPF", StatusEventType.RunningProgress);
                setResult = InsertABKOPF(dwABPOS, ABKAUFART, DISPONUM);
                setReturn.Merge(setResult);
                #endregion

                #region============ABPR=======================
                EventDispatcher.Instance.RaiseStatus("开始创建浆纱ABPR", StatusEventType.RunningProgress); 
                setResult = InsertABPR(dwABPOS);
                setReturn.Merge(setResult);
                #endregion

                #region============ABFOLGE====================
                EventDispatcher.Instance.RaiseStatus("开始创建浆纱ABFOLGE", StatusEventType.RunningProgress); 
                setResult = InsertABFOLGE(dwABPOS, dwDispo["KABFKRS"].ToString(), dwDispo["KABFLFD"].ToString(), dwDispo["KABFPOS"].ToString());
                setReturn.Merge(setResult);
                #endregion

                #region============ABAUFM=====================
                EventDispatcher.Instance.RaiseStatus("开始创建浆纱ABAUFM", StatusEventType.RunningProgress); 
                setResult = InsertABAUFM(dwABPOS, dwBAAUF, dwAB55);
                setReturn.Merge(setResult); 

                #endregion 
                #region============BAAUF=====================
                EventDispatcher.Instance.RaiseStatus("开始创建浆纱BAAUF", StatusEventType.RunningProgress);
                setResult = InsertBAAUF(dwABPOS);
                setReturn.Merge(setResult);
                #endregion 
                #region============BABST=======================
                EventDispatcher.Instance.RaiseStatus("开始创建浆纱BABST", StatusEventType.RunningProgress);
                setResult = InsertBABST(dwABPOS, dwBAAUF, dwBSGROE, dwBSSATZ, dwBHSATZ);
                setReturn.Merge(setResult);
                #endregion
                #region============GAAUF=====================
                EventDispatcher.Instance.RaiseStatus("开始创建浆纱GAAUF", StatusEventType.RunningProgress); 
                setResult = InsertGAAUF(dwABPOS,DISPONUM);
                setReturn.Merge(setResult);
                #endregion 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
         
    }
}